<template>
  <div>
    <div style="height: 500px">
      <FormPanel
        ref="formPanel"
        :cols="2"
        :labelWidth="110"
        :list="formList"
        :isSubmitBtn="false"
        @formChange="formChangeHandle"
        style="margin-top: 20px"
      />
    <AjaxButton :click="saveDialog" type="primary">保存</AjaxButton>

    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
    </div>
  </div>
</template>
<script>
import {
  searchOnceDriveMileage,
  saveMileage
} from '@/api/potenCus/basedata/onceDriveMileage';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'OnceDriveMileage',
  mixins: [dictionary],
  components: {
  },
  data() {
    return {
      formList: this.createFormList()
    };
  },
  created() {
    this.searchMileage()
  },
  methods: {
    async searchMileage() {
      let res = await searchOnceDriveMileage(this.saveData);
      // console.log('单次试驾里程',res)
      var self = res.data
      self.map( (item,index) => {
        if( item.paramCode == "test_drive_mileage" ){
          this.paramValue = Number(item.paramValue)
          this.paramId = item.paramId
        }
      })
      console.log('paramId',this.paramId)
      console.log('paramValue',this.paramValue)
      this.formList[0].initialValue = this.paramValue
    },

    createFormList() {
      return [
        {
          type: 'INPUT_NUMBER',
          label: '单次试驾里程',
          fieldName: 'paramValue',
          placeholder: '请输入',
          initialValue: '',
          rules: [{ required: true, message: '请输入试驾里程', trigger: 'blur'} ],
        }
      ];
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
    async saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData !== null) {
        let res = await saveMileage([{paramId: this.paramId , ...this.saveData}]);
        if (res.resultCode === 200) {
          this.$message.success("保存成功!");
        }
      }
    },
    // closeDialog(param) {
    //   this.$emit('close', false, param);
    // },

  },

};
</script>

<style lang="less" scoped>
</style>
